from ftllibs.champions import *
import sys
import re
import copy

class Champs():
    def __init__(self,parent):
        self.parent=parent
        self.CHAMPS={}
        self.ChampIndex=[]
        self.ModuleIndex=[]
        for i in sys.modules.keys():
            m = re.match('ftllibs.champions.(c_\w+)',i)
            if m:
                self.ModuleIndex.append(m.groups(0)[0])
        self.InitChamps()
        self.CreateLists()

    def InitChamps(self):
        temp=[]
        for j in self.ModuleIndex:
            cmd = "temp.append(%s.Champ())" % (j)
            exec cmd

        for x in temp:
            cid = x.ID
            self.ChampIndex.append(str(cid))
            self.CHAMPS[str(cid)]=x


    def GetChamp(self,champid):
        return self.CHAMPS[str(champid)]

    def GetChampCopy(self,champid):
        return copy.deepcopy(self.CHAMPS[str(champid)])

    def CreateLists(self):
        self.ChampList=[]
        self.ChampName2ID={}
        self.ChampID2Name={}
        for ChampID in self.ChampIndex:
            self.ChampList.append(self.CHAMPS[ChampID].Name)
            self.ChampID2Name[ChampID]=self.CHAMPS[ChampID].Name
            self.ChampName2ID[self.CHAMPS[ChampID].Name]=ChampID

    def GetChampList(self):
        return sorted(self.ChampList)

    def GetChampID(self,name):
        return int(self.ChampName2ID[str(name)])

    def GetChampName(self,champid):
        print "champID:", champid
        return str(self.ChampID2Name[str(champid)])
